package com.atguigu.nio.zerocopy;

import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.Socket;

public class OldIOClient {

    public static void main(String[] args) throws IOException, InterruptedException {
        Socket socket = new Socket("127.0.0.1", 7001);

//        F://terraria.v1.4.1.2.zip
        FileInputStream fileInputStream = new FileInputStream("F://mclc.zip");

        DataOutputStream dataOutputStream = new DataOutputStream(socket.getOutputStream());
        byte[] bytes = new byte[4096];
        long readCount;
        long total = 0;

        long startTime = System.currentTimeMillis();

        while ((readCount = fileInputStream.read(bytes)) >= 0) {
            total += readCount;
            dataOutputStream.write(bytes);
        }
        dataOutputStream.flush();
        dataOutputStream.close();
        System.out.println("发送总字节数：" + total + "，耗时："  + (System.currentTimeMillis() - startTime));
    }
}
